﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Oscilloscope
{
    public partial class Form1 : Form
    {

        private Graphics mCombinedGrahp;
        private Graphics mGraphA;
        private Graphics mGraphB;

        public Form1()
        {
            this.ResizeRedraw = true; 
            InitializeComponent();
            ResizePanel();
            Init();
        }

        private void Init()
        {
            DrawAll();
        }

        private void ResizeAll()
        {
            ResizePanel();
            ClearAll();
        }

        private void ResizePanel()
        {
            panelCombinedSignal.Width = 3 * this.Width / 5;
            panelCombinedSignal.Height = this.Height - 38;
            panelCombinedSignal.Location = new Point(0, 0);

            panelSignalA.Width = this.Width - panelCombinedSignal.Width;
            panelSignalA.Height = panelCombinedSignal.Height / 2;
            panelSignalA.Location = new Point(panelCombinedSignal.Width, 0);

            panelSignalB.Width = this.Width - panelCombinedSignal.Width;
            panelSignalB.Height = panelCombinedSignal.Height / 2;
            panelSignalB.Location = new Point(panelCombinedSignal.Width, panelSignalA.Height);
        }

        private void DrawAll()
        {
            ClearAll();
            panelCombinedSignal.Refresh();
            DrawAllAxis();
        }

        private void ClearAll()
        {
            if(mCombinedGrahp != null)
                mCombinedGrahp.Clear(panelCombinedSignal.BackColor);
        }

        private void DrawAllAxis()
        {
            DrawAxisCombinedSignal();
            DrawAxisA();
            DrawAxisB();
        }

        private void DrawAxisCombinedSignal ()
        {
            if (mCombinedGrahp != null)
                OscilloscopeHelper.DrawAxis(mCombinedGrahp);
        }

        private void DrawAxisA()
        {
            if (mGraphA != null)
                OscilloscopeHelper.DrawAxis(mGraphA);
        }

        private void DrawAxisB()
        {
            if (mGraphB != null)
                OscilloscopeHelper.DrawAxis(mGraphB);
        }

        private void panelCombinedSignal_Paint(object sender, PaintEventArgs e)
        {
            base.OnPaint(e);

            mCombinedGrahp = e.Graphics;
            DrawAxisCombinedSignal();
        }

        private void panelSignalA_Paint(object sender, PaintEventArgs e)
        {
            base.OnPaint(e);

            mGraphA = e.Graphics;
            DrawAxisA();
        }

        private void panelSignalB_Paint(object sender, PaintEventArgs e)
        {
            base.OnPaint(e);

            mGraphB = e.Graphics;
            DrawAxisB();
        }

        private void buttonModifyFirstSignal_Click(object sender, EventArgs e)
        {
            VisibleButtonParametersOne(true);
        }



        private void VisibleButtonParametersOne(bool visible)
        {
            buttonCloseFirstSignal.Visible = visible;
            buttonValidFirstSignal.Visible = visible;
            buttonModifyFirstSignal.Visible = !visible;
            panelParametersPanelFirstPanel.Visible = visible;
        }

        private void buttonCloseFirstSignal_Click(object sender, EventArgs e)
        {
            VisibleButtonParametersOne(false);
        }

        private void buttonValidFirstSignal_Click(object sender, EventArgs e)
        {
            VisibleButtonParametersOne(false);

            //drawall
        }

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            /*base.OnPaint(e);

            mCombinedGrahp = new Graphics();
            DrawAxisCombinedSignal();*/
        }
    }
}
